// component/index/tips/worktime.js
const app = getApp();

Component({
    "options": {
        styleIsolation: 'isolated'
    },
    /**
     * 组件的属性列表
     */
    properties: {
        src: {type: String, value: null},
        tips: {type: String, value: ''}
    },

    /**
     * 组件的初始数据
     */
    data: {},

    lifetimes: {
        attached() {
        }
    },

    observers: {},

    /**
     * 组件的方法列表
     */
    methods: {
        changePic: function (e) {
            return app.func.chooseFileEx(2, 1,
                ([file]) => {
                    return app.func.uploadPromise("/v2/image/upload", file.path, 'file')
                        .then(([code, res]) => {
                            if (code == 3102 || code == 3103) {
                                return app.func.toastPromise('图片内容违规').then((resolve, reject) => {
                                    reject();
                                });
                            } else {
                                var src = res.data;
                                this.setData({
                                    src: src
                                });
                                this.triggerEvent('input', {value: src})
                            }
                        }).catch(console.error);
                });
        }
    }
});
